package org.lc.platform.base.handler;

import lombok.extern.slf4j.Slf4j;
import org.lc.platform.base.exception.BusinessException;
import org.lc.platform.base.exception.SystemException;
import org.lc.platform.base.result.Result;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 异常处理器
 * 处理的异常都是主动不影响正常使用的
 */
@RestControllerAdvice
@Order(Ordered.LOWEST_PRECEDENCE - 3)
@Slf4j
public class CustomExceptionHandler {
    /**
     * 处理业务逻辑异常
     */
    @ExceptionHandler(BusinessException.class)
    public Result<?> handlerBusinessExceptionException(BusinessException e) {
        return Result.error(e.getCode(),e.getMsg());
    }

    /**
     *
     * 处理系统异常
     */
    @ExceptionHandler(SystemException.class)
    public Result<?> handlerSystemException(SystemException e) {
        return Result.error(e.getCode(),e.getMsg());
    }


}
